package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	GoodsTitle string  `gorm:"type:varchar(100);not null;index;comment:商品标题"`
	GoodsPrice float64 `gorm:"type:decimal(10,2);default:0"`
	GoodsCover string  `gorm:"type:varchar(255)"`
	GoodsStock int     `gorm:"type:int"`
	LikeCount  int     `gorm:"type:int"`
}

func (g *Goods) List(page, PageSize int) (list []*Goods, err error) {
	err = DB.Order("like_count desc").Offset((page - 1) * PageSize).Limit(PageSize).Order("").Find(&list).Error
	return
}
func (g *Goods) Detail(goodsId int) error {
	return DB.First(&g, goodsId).Error
}
